{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Platform : win32 [win32/linux]\n",
      "Systerm  : 3.6.10 (default, Mar  5 2020, 10:17:47) [MSC v.1900 64 bit (AMD64)] \n",
      "当前时间：20201022 01:53:22\n",
      "当前路径: D:\\Desktop\\NoteBooks00\\环境布置\n"
     ]
    }
   ],
   "source": [
    "import time \n",
    "import os \n",
    "import sys\n",
    "\n",
    "print('Platform : {} [win32/linux]'.format(sys.platform))  # 当前平台信息 \n",
    "print('Systerm  : {} '.format(sys.version))\n",
    "print('当前时间：{}'.format(time.strftime('%Y%m%d %H:%M:%S', time.localtime(time.time()))))\n",
    "print('当前路径: {}'.format(os.path.abspath(os.path.curdir)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 记录当前环境 所有依赖包及其精确的版本号。以便新环境部署。  \n",
    "\n",
    "### 生成requirements.txt文件\n",
    " pip freeze > requirements.txt\n",
    " \n",
    "### 安装requirements.txt依赖\n",
    " pip install -r requirements.txt\n",
    "\n",
    "[Python使用conda安装requirement.txt的扩展包](https://blog.csdn.net/weixin_45092662/article/details/106906719)  \n",
    "\n",
    "### 本地打开 jupyter lab:  \n",
    "jupyter lab --notebook-dir=D:\\   "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "cat: requirements.txt: No such file or directory\n"
     ]
    }
   ],
   "source": [
    "! cat requirements.txt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "absl-py==0.9.0\n",
      "alabaster==0.7.12\n",
      "anaconda-client==1.7.2\n",
      "anaconda-navigator==1.9.6\n",
      "anaconda-project==0.8.2\n",
      "asn1crypto==0.24.0\n",
      "astroid==2.1.0\n",
      "astropy==3.1\n",
      "atomicwrites==1.2.1\n",
      "attrs==18.2.0\n",
      "Babel==2.6.0\n",
      "backcall==0.1.0\n",
      "backports.os==0.1.1\n",
      "backports.shutil-get-terminal-size==1.0.0\n",
      "beautifulsoup4==4.6.3\n",
      "bitarray==0.8.3\n",
      "bkcharts==0.2\n",
      "blaze==0.11.3\n",
      "bleach==3.0.2\n",
      "blis==0.2.4\n",
      "bokeh==1.0.2\n",
      "boto==2.49.0\n",
      "Bottleneck==1.2.1\n",
      "certifi==2018.11.29\n",
      "cffi==1.11.5\n",
      "chardet==3.0.4\n",
      "Click==7.0\n",
      "cloudpickle==0.6.1\n",
      "clyent==1.2.2\n",
      "colorama==0.4.1\n",
      "comtypes==1.1.7\n",
      "conda==4.8.2\n",
      "conda-build==3.17.6\n",
      "conda-package-handling==1.6.0\n",
      "conda-verify==3.1.1\n",
      "contextlib2==0.5.5\n",
      "cryptography==2.4.2\n",
      "cycler==0.10.0\n",
      "cymem==2.0.3\n",
      "Cython==0.29.2\n",
      "cytoolz==0.9.0.1\n",
      "dask==1.0.0\n",
      "datashape==0.5.4\n",
      "decorator==4.3.0\n",
      "defusedxml==0.5.0\n",
      "distributed==1.25.1\n",
      "docutils==0.14\n",
      "entrypoints==0.2.3\n",
      "et-xmlfile==1.0.1\n",
      "fastcache==1.0.2\n",
      "filelock==3.0.10\n",
      "Flask==1.0.2\n",
      "Flask-Cors==3.0.7\n",
      "future==0.17.1\n",
      "gevent==1.3.7\n",
      "glob2==0.6\n",
      "greenlet==0.4.15\n",
      "grpcio==1.23.0\n",
      "gTTS==2.1.1\n",
      "gTTS-token==1.1.3\n",
      "h5py==2.8.0\n",
      "heapdict==1.0.0\n",
      "html5lib==1.0.1\n",
      "idna==2.8\n",
      "imageio==2.4.1\n",
      "imagesize==1.1.0\n",
      "importlib-metadata==0.6\n",
      "ipykernel==5.1.0\n",
      "ipython==7.2.0\n",
      "ipython-genutils==0.2.0\n",
      "ipywidgets==7.4.2\n",
      "isort==4.3.4\n",
      "itsdangerous==1.1.0\n",
      "jdcal==1.4\n",
      "jedi==0.13.2\n",
      "jieba==0.42.1\n",
      "Jinja2==2.10\n",
      "jsonschema==2.6.0\n",
      "jupyter==1.0.0\n",
      "jupyter-client==5.2.4\n",
      "jupyter-console==6.0.0\n",
      "jupyter-core==4.4.0\n",
      "jupyterlab==0.35.3\n",
      "jupyterlab-server==0.2.0\n",
      "Keras==2.2.4\n",
      "Keras-Applications==1.0.8\n",
      "Keras-Preprocessing==1.1.2\n",
      "keyring==17.0.0\n",
      "kiwisolver==1.0.1\n",
      "lazy-object-proxy==1.3.1\n",
      "libarchive-c==2.8\n",
      "lightgbm==2.3.1\n",
      "llvmlite==0.26.0\n",
      "locket==0.2.0\n",
      "lxml==4.2.5\n",
      "Markdown==3.2.1\n",
      "MarkupSafe==1.1.0\n",
      "mathparse==0.1.2\n",
      "matplotlib==3.0.2\n",
      "mccabe==0.6.1\n",
      "menuinst==1.4.14\n",
      "mistune==0.8.4\n",
      "mkl-fft==1.0.6\n",
      "mkl-random==1.0.2\n",
      "more-itertools==4.3.0\n",
      "mpmath==1.1.0\n",
      "msgpack==0.5.6\n",
      "multipledispatch==0.6.0\n",
      "murmurhash==1.0.2\n",
      "navigator-updater==0.2.1\n",
      "nbconvert==5.4.0\n",
      "nbformat==4.4.0\n",
      "networkx==2.2\n",
      "nltk==3.4\n",
      "nose==1.3.7\n",
      "notebook==5.7.4\n",
      "numba==0.41.0\n",
      "numexpr==2.6.8\n",
      "numpy==1.15.4\n",
      "numpydoc==0.8.0\n",
      "odo==0.5.1\n",
      "olefile==0.46\n",
      "openpyxl==2.5.12\n",
      "packaging==18.0\n",
      "pandas==0.23.4\n",
      "pandocfilters==1.4.2\n",
      "parso==0.3.1\n",
      "partd==0.3.9\n",
      "path.py==11.5.0\n",
      "pathlib2==2.3.3\n",
      "patsy==0.5.1\n",
      "pep8==1.7.1\n",
      "pickleshare==0.7.5\n",
      "Pillow==5.3.0\n",
      "Pint==0.11\n",
      "pkginfo==1.4.2\n",
      "plac==0.9.6\n",
      "pluggy==0.8.0\n",
      "ply==3.11\n",
      "preshed==2.0.1\n",
      "prometheus-client==0.5.0\n",
      "prompt-toolkit==2.0.7\n",
      "protobuf==3.11.4\n",
      "psutil==5.4.8\n",
      "py==1.7.0\n",
      "pycodestyle==2.4.0\n",
      "pycosat==0.6.3\n",
      "pycparser==2.19\n",
      "pycrypto==2.6.1\n",
      "pycurl==7.43.0.2\n",
      "pyflakes==2.0.0\n",
      "Pygments==2.3.1\n",
      "pylint==2.2.2\n",
      "pyodbc==4.0.25\n",
      "pyOpenSSL==18.0.0\n",
      "pyparsing==2.3.0\n",
      "pypinyin==0.39.1\n",
      "PySocks==1.6.8\n",
      "pytest==4.0.2\n",
      "pytest-arraydiff==0.3\n",
      "pytest-astropy==0.5.0\n",
      "pytest-doctestplus==0.2.0\n",
      "pytest-openfiles==0.3.1\n",
      "pytest-remotedata==0.3.1\n",
      "python-dateutil==2.8.1\n",
      "pytz==2018.7\n",
      "PyWavelets==1.0.1\n",
      "pywin32==223\n",
      "pywinpty==0.5.5\n",
      "PyYAML==3.13\n",
      "pyzmq==17.1.2\n",
      "QtAwesome==0.5.3\n",
      "qtconsole==4.4.3\n",
      "QtPy==1.5.2\n",
      "redis==3.5.3\n",
      "redis-py-cluster==2.1.0\n",
      "requests==2.21.0\n",
      "rope==0.11.0\n",
      "ruamel-yaml==0.15.46\n",
      "scikit-image==0.14.1\n",
      "scikit-learn==0.20.1\n",
      "scipy==1.1.0\n",
      "seaborn==0.9.0\n",
      "Send2Trash==1.5.0\n",
      "simplegeneric==0.8.1\n",
      "singledispatch==3.4.0.3\n",
      "six==1.12.0\n",
      "snowballstemmer==1.2.1\n",
      "sortedcollections==1.0.1\n",
      "sortedcontainers==2.1.0\n",
      "spacy==2.1.9\n",
      "Sphinx==1.8.2\n",
      "sphinxcontrib-websupport==1.1.0\n",
      "spyder==3.3.2\n",
      "spyder-kernels==0.3.0\n",
      "SQLAlchemy==1.3.16\n",
      "srsly==1.0.2\n",
      "statsmodels==0.9.0\n",
      "sympy==1.3\n",
      "tables==3.4.4\n",
      "tblib==1.3.2\n",
      "tensorboard==1.15.0\n",
      "terminado==0.8.1\n",
      "testpath==0.4.2\n",
      "thinc==7.0.8\n",
      "toolz==0.9.0\n",
      "torch==1.5.0\n",
      "torchvision==0.5.0\n",
      "tornado==5.1.1\n",
      "tqdm==4.28.1\n",
      "traitlets==4.3.2\n",
      "unicodecsv==0.14.1\n",
      "urllib3==1.24.1\n",
      "wasabi==0.6.0\n",
      "wcwidth==0.1.7\n",
      "webencodings==0.5.1\n",
      "Werkzeug==0.14.1\n",
      "widgetsnbextension==3.4.2\n",
      "win-inet-pton==1.0.1\n",
      "win-unicode-console==0.5\n",
      "wincertstore==0.2\n",
      "wrapt==1.10.11\n",
      "xlrd==1.2.0\n",
      "XlsxWriter==1.1.2\n",
      "xlwings==0.15.1\n",
      "xlwt==1.3.0\n",
      "zict==0.1.3\n"
     ]
    }
   ],
   "source": [
    "! pip freeze "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "--- \n",
    "### 导出conda环境，导出格式为.yml文件   \n",
    "conda env export > requirements.yml\n",
    "### 根据 requirements.yml 创建conda 环境\n",
    "conda env create -f requirements.yml"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "! cat requirements.yml"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple\n",
      "Collecting pypinyin==0.39.1 (from -r requirements.txt (line 1))\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/38/c2/2a834bf95f3dfab1e7dbafe4bb88140ac40d0ae35bb737994abfbb54cde9/pypinyin-0.39.1-py2.py3-none-any.whl (780kB)\n",
      "Installing collected packages: pypinyin\n",
      "Successfully installed pypinyin-0.39.1\n"
     ]
    }
   ],
   "source": [
    "! pip install -r requirements.txt  -i  https://pypi.tuna.tsinghua.edu.cn/simple"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "#  [Redis](https://pypi.org/project/redis-py-cluster/)\n",
    "[Docker 安装 Redis](https://www.runoob.com/docker/docker-install-redis.html)  \n",
    "[Linux_基于Docker搭建Redis集群](https://segmentfault.com/a/1190000010131816)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple\n",
      "Requirement already satisfied: redis-py-cluster in c:\\programdata\\anaconda3\\lib\\site-packages (2.1.0)\n",
      "Requirement already satisfied: redis<4.0.0,>=3.0.0 in c:\\programdata\\anaconda3\\lib\\site-packages (from redis-py-cluster) (3.5.3)\n"
     ]
    }
   ],
   "source": [
    "! pip install redis-py-cluster -i  https://pypi.tuna.tsinghua.edu.cn/simple\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Redis 调用程序 \n",
    "class myRedis(object):\n",
    "    def __init__(self, redis_type=None, **args):\n",
    "        if redis_type == \"cluster\":\n",
    "            import rediscluster\n",
    "            print('Cluster   Version:{}'.format(rediscluster.__version__))\n",
    "            self.r_conn = rediscluster.StrictRedisCluster(**args)\n",
    "        else:\n",
    "            import redis\n",
    "            print('Single    Version:{}'.format(redis.__version__))\n",
    "            self.r_conn = redis.StrictRedis(**args)\n",
    "\n",
    "    def GetValue(self, name):\n",
    "        return self.r_conn.get(name).decode()\n",
    "\n",
    "    def IncrValue(self, name):\n",
    "        return self.r_conn.incr(name)\n",
    "\n",
    "    def SetValue(self, name, value):\n",
    "        self.r_conn.set(name, value)\n",
    "\n",
    "    def GetSetValue(self, name, value):\n",
    "        return self.r_conn.getset(name, value)\n",
    "  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Single    Version:3.5.3\n",
      "None\n",
      "获取值： test\n",
      "b'0'\n",
      "获取值： 0\n"
     ]
    }
   ],
   "source": [
    "#单点\n",
    "conn_dict={\"host\": \"192.168.0.100\", \"port\": 6379}\n",
    "redis_type='single'\n",
    "myredis = myRedis(redis_type,**conn_dict)\n",
    "print(myredis.SetValue('name','test'))\n",
    "print('获取值：', myredis.GetValue('name'))\n",
    "print(myredis.GetSetValue('name1',0))\n",
    "print('获取值：',myredis.GetValue('name1'))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [],
   "source": [
    "# # cluster  集群  (未调试成攻，暂时搁置)\n",
    "# conn_dict = {\"startup_nodes\": [{'host': '192.168.0.100', 'port': 6379},\n",
    "#                                {'host': '192.168.0.100', 'port': 6380},\n",
    "#                                {'host': '192.168.0.100', 'port': 6381}]}\n",
    "# redis_type = 'cluster'\n",
    "# myredis = myRedis(redis_type, **conn_dict)\n",
    "# print(myredis.SetValue('name', 'test'))\n",
    "# print(myredis.GetValue('name'))\n",
    "# print(myredis.GetSetValue('name', 0))\n",
    "# print(myredis.GetValue('name'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [],
   "source": [
    "! pip freeze > requirements.txt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/d/Desktop/NoteBooks00\n"
     ]
    }
   ],
   "source": [
    "! pwd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "python(py37)",
   "language": "python",
   "name": "py36"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
